package cn.uin.domain.auth.service.user.login.handle;

import cn.uin.domain.auth.model.entity.UserInfoDetailEntity;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Collection;

/**
 * @ClassName CustomPermissionEvaluator
 * @Description: 自定义对hasPermission的处理，实现PermissionEvaluator接口
 * @Author: Administrator
 * @CreateDate: 2025/10/25 14:11
 * @Version: 1.0
 */
@Component
public class CustomPermissionEvaluator implements PermissionEvaluator {
	@Override
	public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
		//获取当前用户权限
		Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
		if(authorities!=null && authorities.size()>0){
			for (GrantedAuthority a : authorities){
				if(permission.equals(a.getAuthority())){
					return true;
				}
			}
		}
		return false;
	}

	@Override
	public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) {
		return false;
	}
}
